package com.cardone.platform.authority.controller;

import java.util.List;
import java.util.concurrent.Callable;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cardone.common.dto.PaginationDto;
import com.cardone.common.dto.ReturnDataDto;
import com.cardone.common.util.ReturnDataUtils;
import com.cardone.context.ContextHolder;
import com.cardone.platform.authority.dto.UsGroupUserDto;
import com.cardone.platform.authority.service.UsGroupUserService;

/**
 * 用户组与用户
 *
 * @author yaohaitao
 */
@Deprecated
@Setter
@Slf4j
@RequestMapping("/authority/usGroupUser/")
@Controller
public class UsGroupUserController {
	/**
	 * 初始化数据绑定
	 *
	 * @param webDataBinder
	 *          数据绑定
	 */
	// @InitBinder
	// @Deprecated
	// public void initBinder(final WebDataBinder webDataBinder) {
	// }

	/**
	 * 用户组与用户：删除
	 *
	 * @param deleteUsGroupUser
	 *          用户组与用户对象
	 * @return 处理结果，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "delete.json" }, method = RequestMethod.POST)
	@ResponseBody
	public Callable<ReturnDataDto<String>> deleteJson(final UsGroupUserDto deleteUsGroupUser) {
		return new Callable<ReturnDataDto<String>>() {
			@Override
			public ReturnDataDto<String> call() throws Exception {
				try {
					ContextHolder.getBean(UsGroupUserService.class).deleteByIds(deleteUsGroupUser);

					return ReturnDataUtils.newReturnData();
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UsGroupUserController.log);
				}
			}
		};
	}

	/**
	 * 用户组与用户：分页查询
	 *
	 * @param findUsGroupUser
	 *          用户组与用户对象
	 * @param model
	 *          上下文映射
	 */
	@Deprecated
	@RequestMapping(value = { "edit.html" })
	public void editHtml(final UsGroupUserDto findUsGroupUser, final Model model) {
		final UsGroupUserDto usGroupUser = ContextHolder.getBean(UsGroupUserService.class).findById(UsGroupUserDto.class, findUsGroupUser);

		model.addAttribute("usGroupUser", usGroupUser);
	}

	/**
	 * 用户组与用户：编辑
	 *
	 * @param findUsGroupUser
	 *          用户组与用户对象
	 * @return 实体对象集，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "findById.json" })
	@ResponseBody
	public Callable<ReturnDataDto<UsGroupUserDto>> findByIdJson(final UsGroupUserDto findUsGroupUser, final Model model) {
		return new Callable<ReturnDataDto<UsGroupUserDto>>() {
			@Override
			public ReturnDataDto<UsGroupUserDto> call() throws Exception {
				try {
					final UsGroupUserDto usGroupUser = ContextHolder.getBean(UsGroupUserService.class).findById(UsGroupUserDto.class, findUsGroupUser);

					return ReturnDataUtils.newReturnData(usGroupUser);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UsGroupUserController.log);
				}
			}
		};
	}

	/**
	 * 用户组与用户：查询
	 *
	 * @param findListUsGroupUser
	 *          用户组与用户对象
	 * @return 用户组与用户对象集合，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "findListByLikeCode.json" })
	@ResponseBody
	public Callable<ReturnDataDto<List<UsGroupUserDto>>> findListByLikeCodeJson(final UsGroupUserDto findListUsGroupUser) {
		return new Callable<ReturnDataDto<List<UsGroupUserDto>>>() {
			@Override
			public ReturnDataDto<List<UsGroupUserDto>> call() throws Exception {
				try {
					final List<UsGroupUserDto> usGroupUserList = ContextHolder.getBean(UsGroupUserService.class).findListByLikeCode(UsGroupUserDto.class, findListUsGroupUser);

					return ReturnDataUtils.newReturnData(usGroupUserList);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UsGroupUserController.log);
				}
			}
		};
	}

	/**
	 * 用户组与用户：分页查询
	 *
	 * @param paginationUsGroupUser
	 *          用户组与用户对象
	 * @return 分页，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "paginationByLikeCode.json" })
	@ResponseBody
	public Callable<ReturnDataDto<PaginationDto<UsGroupUserDto>>> paginationByLikeCodeJson(final UsGroupUserDto paginationUsGroupUser) {
		return new Callable<ReturnDataDto<PaginationDto<UsGroupUserDto>>>() {
			@Override
			public ReturnDataDto<PaginationDto<UsGroupUserDto>> call() throws Exception {
				try {
					final PaginationDto<UsGroupUserDto> usGroupUserPagination = ContextHolder.getBean(UsGroupUserService.class).paginationByLikeCode(UsGroupUserDto.class, paginationUsGroupUser);

					return ReturnDataUtils.newReturnData(usGroupUserPagination);
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UsGroupUserController.log);
				}
			}
		};
	}

	/**
	 * 用户组与用户：分页查询
	 *
	 * @param paginationUsGroupUser
	 *          用户组与用户对象
	 * @param model
	 *          上下文映射
	 */
	@Deprecated
	@RequestMapping(value = { "pagination.html" })
	public void paginationHtml(final UsGroupUserDto paginationUsGroupUser, final Model model) {
		final PaginationDto<UsGroupUserDto> usGroupUserPagination = ContextHolder.getBean(UsGroupUserService.class).paginationByLikeCode(UsGroupUserDto.class, paginationUsGroupUser);

		model.addAttribute("usGroupUserPagination", usGroupUserPagination);
	}

	/**
	 * 用户组与用户：保存
	 *
	 * @param saveUsGroupUser
	 *          用户组与用户对象
	 * @return 处理结果，json格式
	 */
	@Deprecated
	@RequestMapping(value = { "save.json" })
	@ResponseBody
	public Callable<ReturnDataDto<String>> saveJson(final UsGroupUserDto saveUsGroupUser) {
		return new Callable<ReturnDataDto<String>>() {
			@Override
			public ReturnDataDto<String> call() throws Exception {
				try {
					ContextHolder.getBean(UsGroupUserService.class).saveByIdOrCode(UsGroupUserDto.class, saveUsGroupUser);

					return ReturnDataUtils.newReturnData();
				} catch (final Exception e) {
					return ReturnDataUtils.newReturnData(e, UsGroupUserController.log);
				}
			}
		};
	}
}
